import React, { useEffect, useState } from 'react'
import Item from './item/index.jsx'
import PubSub from 'pubsub-js'

export default function List() {
//初始化订阅。用来保存传过来的数据
const [searchList,setSearchList] = useState([])
//初始化订阅
useEffect(()=>{
    //订阅数据，数据名称 还有第二个参数为数据data
    PubSub.subscribe("github", (_, data) => {
        // console.log(data);
        setSearchList(data.data.items)
    })
})

  return (
    <div className="row">
        {/* 遍历上面订阅后的数据 */}
        {
            searchList.map((item)=>{
                return <Item key={item.id} {...item}/>
            })
        }
  </div>
  )
}
